/**
 * StringBuilder类的用法；StringBuffer 和 StringBuilder 类方法一样；
 *  区别: StringBuffer(线程安全),效率慢; StringBuilder(不安全),效率快;
 *  效率: StringBuilder >  StringBuffer  >  String
 */
public class StringBuilderDemo {
    public static void main(String[] args) {
        //可以直接加入构造参数中
        StringBuilder stringBuilder=new StringBuilder(/*"abc"*/);

        //append方法添加连接字符串
        stringBuilder.append("abc");
        stringBuilder.append(1);
        stringBuilder.append(true);
        stringBuilder.append(8.8);
        stringBuilder.append('中');
        System.out.println(stringBuilder);//abc1true8.8中

        /**
         * 链式编程:方法返回值是一个对象,可以继续调用方法
         */
        StringBuilder bu=new StringBuilder();
        bu.append("abc").append(1).append(true).append(8.8).append('中');
        System.out.println(bu);//abc1true8.8中


        /**
         * String > StringBuilder  构造方法传递
         * StringBuilder > String toString 方法
         */
        // String -> StringBuilder
        String str = "hello";
        StringBuilder stringBuilder1 = new StringBuilder(str);
        System.out.println("bu:"+stringBuilder1);

        // StringBuilder -> String
        String s = stringBuilder1.toString();
        System.out.println("s:"+s);



    }
}
